package com.yumeng.common.helper;

import io.micrometer.common.util.StringUtils;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Objects;

/**
 * @author wxd
 * @date 2024/5/28 下午3:46
 */
public class AssertHelper {

    public static void assertContains(String str1, String str2){
        Assert.isTrue(str1.contains(str2), str1 + "-" + str2);
    }

    public static void assertStartsWith(String str1, String str2){
        Assert.isTrue(str1.startsWith(str2), str1 + "-" + str2);
    }

    public static void assertEquals(Object obj1, Object obj2){
        Assert.isTrue(Objects.equals(obj1, obj2), obj1 + "-" + obj2);
    }

    public static void assertNotEquals(Object obj1, Object obj2){
        Assert.isTrue(!Objects.equals(obj1, obj2), obj1 + "-" + obj2);
    }

    public static void assertEquals(Object obj1, Object obj2, String message){
        Assert.isTrue(Objects.equals(obj1, obj2), message);
    }

    public static void assertNotEquals(Object obj1, Object obj2, String message){
        Assert.isTrue(!Objects.equals(obj1, obj2), message);
    }

    public static void assertIsTrue(boolean expression, String message){
        Assert.isTrue(expression, message);
    }

    public static void assertIsNull(Object obj, String message){
        Assert.isNull(obj, message);
    }

    public static void assertNotNull(Object obj, String message){
        Assert.notNull(obj, message);
    }

    public static void assertNotBlank(String objStr, String message){
        Assert.isTrue(StringUtils.isNotBlank(objStr), message);
    }

    public static void assertNotEmpty(List list, String message){
        Assert.isTrue(list != null && list.size() > 0, message);
    }

    public static void assertArrayNotEmpty(String message, String... strs){
        Assert.isTrue(strs != null && strs.length > 0, message);
    }

    public static void assertArrayNotBlank(String message, String... strs){
        for (String str : strs){
            Assert.isTrue(StringUtils.isNotBlank(str), message);
        }
    }

}
